#!/usr/bin/python
#coding:utf-8


import MySQLdb

def con(host,user,passwd,db,sql):
    # 打开数据库连接
    db = MySQLdb.connect(host, user, passwd, db, charset='utf8' )
    # 使用cursor()方法获取操作游标
    cursor = db.cursor()
    # 使用execute方法执行SQL语句
    cursor.execute(sql)
    # 使用 fetchone() 方法获取一条数据
    data = cursor.fetchall()
    # 关闭数据库连接
    db.close()
    return data

if __name__ == "__main__":

    host = '192.168.1.196'
    user = 'root'
    passwd = 'root'
    db = 'mutouyun'
    sql = 'show tables'
    data = con(host, user, passwd, db, sql)
    for i in data:
        mysql ='show table status from %s where name="%s"' % (db,i[0])
        data = con(host, user, passwd, db, mysql)
        print i[0],data[0][1]